import request from '@/common/utils/request'
import md5 from 'js-md5'

function formatSign(params) {
    var signstr = JSON.stringify(JSON.parse(params))
    var rule = '"'
    var regS = new RegExp(rule, 'g')
    var rule2 = ':'
    var regS2 = new RegExp(rule2, 'g')
    signstr = signstr.replace(regS, '')
    signstr = signstr.replace(regS2, '=')
    // eslint-disable-next-line
    signstr = signstr.replace(/\\/g, "")
    return signstr
}

export function fmRequest(url, method, queryType, params) {
    if (queryType === 'body') {
        const data = params
        return request({
            url,
            method,
            data
        })
    } else {
        return request({
            url,
            method,
            params
        })
    }
}

// 查询下拉字典数据:[{"formColumnId":21121,"formColumnUsName":"sql13","formColumnGuiType":"sql"}]
export function getselectdatasAll(params) {
    return request({
        url: '/dict/getselectdatasAll.action',
        method: 'post',
        params
    })
}

// 列表业务数据:
// {"order":"asc","offset":0,"limit":10,"containerParam":{},"paramsMap":{},"requestParam":{"ORGVORGANIZATION_DEPCODE":""},"filter":{"ORGDEPARTMENT_DEPCODE":"","ORGDEPARTMENT_DEPGRADE":"","ORGDEPARTMENT_CNAME":""},"userIds":null,"formId":"685","isView":null,"heightGrade":[]}
export function cardformInitData(params) {
    // const params = { 'order': 'asc', 'offset': 0, 'limit': 10, 'containerParam': {}, 'paramsMap': {}, 'requestParam': { 'ORGVORGANIZATION_DEPCODE': '' }, 'filter': { 'ORGDEPARTMENT_DEPCODE': '', 'ORGDEPARTMENT_DEPGRADE': '', 'ORGDEPARTMENT_CNAME': '' }, 'userIds': null, 'formId': '685', 'isView': null, 'heightGrade': [] }
    const data = JSON.stringify(params)
    return request({
        url: '/form/cardformInitData.action',
        method: 'post',
        data
    })
}

// 用户字段权限
export function queryCardFormColumnsWithUserId(formId) {
    return request({
        url: `/form/queryCardFormColumnsWithUserId.action?formId=${formId}`,
        method: 'get'
    })
}

// 用户按钮权限
export function queryCardFormButtonsWithUserId(formId) {
    return request({
        url: `/form/queryCardFormButtonsWithUserId.action?formId=${formId}`,
        method: 'get'
    })
}

// cardformInitColumn
// 字段明细
// export function cardformInitColumn(formId) {
//     const params = { 'order': 'asc', 'offset': 0, 'limit': 10, 'containerParam': {}, 'paramsMap': {}, 'requestParam': { 'ORGVORGANIZATION_DEPCODE': '' }, 'filter': { 'ORGDEPARTMENT_DEPCODE': '', 'ORGDEPARTMENT_DEPGRADE': '', 'ORGDEPARTMENT_CNAME': '' }, 'userIds': null, 'formId': '685', 'isView': null, 'heightGrade': [] }
//     const data = JSON.stringify(params)
//     return request({
//         url: '/form/cardformInitColumn.action',
//         method: 'post',
//         data
//     })
// }

// questionModel/searchganttchartdata.action
export function searchganttchartdata(formId) {
    return request({
        url: `/questionModel/searchganttchartdata.action`,
        method: 'get'
    })
}
// questionModel/searchquestiondate.action
export function searchquestiondate(formId) {
    return request({
        url: `/questionModel/searchquestiondate.action?formId=${formId}`,
        method: 'get'
    })
}

export function getDictDatasAll(formId) {
    return request({
        url: `/dict/getDictDatasAll.action?formId=${formId}`,
        method: 'get'
    })
}

export function searchcolumdisplay(formId) {
    return request({
        url: `/colum/searchcolumdisplay.action?formid=${formId}`,
        method: 'get'
    })
}

export function savecolumdisplay(json) {
    return request({
        url: '/colum/savecolumdisplay.action',
        method: 'get',
        headers: {
            'json': JSON.stringify(json)
        }
    })
}

// /internationalization/gettranslation.action?formid=55
// 国际化
export function internation(formid) {
    return request({
        url: `/internationalization/gettranslation.action?formid=${formid}`,
        method: 'get'
    })
}

// tree
export function queryTreeSolution(solutionId, id, ORGVORGANIZATION_ID, lv) {
    let url
    if (!ORGVORGANIZATION_ID && !lv) {
        url = `/form/getTreeSolutionById.action?solutionId=${solutionId}`
    } else {
        url = `/form/getTreeSolutionById.action?solutionId=${solutionId}&${id}=${ORGVORGANIZATION_ID}&lv=${lv}`
    }

    return request({
        url: url,
        method: 'get'
    })
}

// 批量保存数据接口
export function batchSaveButtonSave(formId, params) {
    const data = JSON.stringify(params)
    return request({
        url: `/form/batchSaveButtonSave.action?formId=${formId}`,
        method: 'post',
        data
    })
}

// /form/removeData.action?sign=d2c9a1a835aa13fee8d81138a90689b7
// 表单数据删除
export function removeData(params) {
    const data = JSON.stringify(params)
    const sign = md5(formatSign(data))
    return request({
        url: `/form/removeData2.action?sign=${sign}`,
        method: 'post',
        data
    })
}

// /POST /form/saveButtonSave.action?sign=556d3c3eb345cceb47834de84471fb0e 表单数据增加
// 表单数据增加
export function saveButtonSave(params) {
    const data = JSON.stringify(params)
    const sign = md5(formatSign(data))
    return request({
        url: `/form/saveButtonSave.action?sign=${sign}`,
        method: 'post',
        data
    })
}

export function findFormList(formParam) {
    return request({
        url: `/form/findFormList.action?sort=form_def_id&order=asc&offset=0&limit=10&condition=${formParam}&pageSize=1&folderTreeCode=0&_=1551792&swaggerUserCode=sysadmin`,
        method: 'get'
    })
}

export function queryFormLayOutDetail(formId) {
    return request({
        url: `/formlayout/queryFormLayOutDetail.action?formid=${formId}&swaggerUserCode=sysadmin`,
        method: 'get'
    })
}

export function updateFormLayOut(formId, templateList) {
    const data = JSON.stringify(templateList)
    return request({
        url: `/formlayout/updateFormLayOut.action?formid=${formId}&folder_id=111&swaggerUserCode=sysadmin`,
        method: 'post',
        data
    })
}

// 获取图表表单数据
export function getEchartsDatas(formId) {
    return request({
        url: `/echarts/getEchartsDatas.action?formId=${formId}`,
        method: 'get'
    })
}

// 获取下载表单数据
export function getFormField(formId) {
    return request({
        url: `/form/getFormField.action?formId=${formId}`,
        method: 'post'
    })
}

// /myehr/form/getImportFileHead.action?fileid='+fileid
export function getImportFileHead(fileid) {
    return request({
        url: `/form/getImportFileHead.action?fileid=${fileid}`,
        method: 'post'
    })
}

// /myehr/form/importExcelData.action?importType=old
export function importExcelData(importType, params) {
    const data = JSON.stringify(params)
    return request({
        url: `/form/importExcelData.action?importType=${importType}`,
        method: 'post',
        data
    })
}

// '/myehr/record/recording.action?formid='+formId,
export function recording(formid) {
    return request({
        url: `/form/record/recording.action?formid=${formid}`,
        method: 'post'
    })
}

// /announcement/exportS.action
export function exportField(filterdata) {
    const data = JSON.stringify(filterdata)
    return request({
        url: `/announcement/exportS.action`,
        method: 'post',
        data
    })
}

// /myehr/form/getExcSolutionByFormId.action?formButtonId='+formButtonId+'&formId='+formId
export function getExcSolutionByFormId(formButtonId, formId) {
    return request({
        url: `/form/getExcSolutionByFormId.action?formButtonId=${formButtonId}&formId=${formId}`,
        method: 'post'
    })
}

// /myehr/form/getSysRuleBySolutionId.action?solutionId='+solutionId
export function getSysRuleBySolutionId(solutionId) {
    return request({
        url: `/form/getSysRuleBySolutionId.action?solutionId=${solutionId}`,
        method: 'post'
    })
}

// /myehr/form/checkAndExcSolutionParams.action?ruleIds='+ruleIds+'&formId='+formId+'&buttonId='+buttonId
export function checkAndExcSolutionParams(ruleIds, formId, buttonId) {
    return request({
        url: `/form/checkAndExcSolutionParams.action?ruleIds=${ruleIds}&formId=${formId}&buttonId=${buttonId}`,
        method: 'post'
    })
}

// /myehr/form/excRule.action
export function excRule(ruleIds, formId, buttonId) {
    const data = { ruleIds, formId, buttonId }
    return request({
        url: `/form/excRule.action`,
        method: 'post',
        data: JSON.stringify(data)
    })
}

// /myehr/form/exportCardformInitData.action
export function exportCardformInitData(data) {
    return request({
        url: `/form/exportCardformInitData.action`,
        method: 'post',
        data: JSON.stringify(data)
    })
}

// 表单数据删除
export function removeDataByButton(params) {
    const data = JSON.stringify(params)
    const sign = md5(formatSign(data))
    return request({
        url: `/form/removeData.action?sign=${sign}`,
        method: 'post',
        data: data
    })
}

// http://119.254.89.122:9882/myehr/CardForm/SaveCardForm.action?swaggerUserCode=sysadmin
export function SaveCardForm(data) {
    return request({
        url: `/CardForm/SaveCardForm.action?swaggerUserCode=sysadmin`,
        method: 'post',
        data: JSON.stringify(data)
    })
}

export function executeSql(data) {
    return request({
        url: `/form/execButtonExecSql.action`,
        method: 'post',
        data: JSON.stringify(data)
    })
}

// /myehr/CardForm/searchCardForm.action?formid=XXX&swaggerUserCode=sysadmin
export function searchCardForm(formid) {
    return request({
        url: `/CardForm/searchCardForm.action?formid=${formid}&swaggerUserCode=sysadmin`,
        method: 'post'
    })
}

// 卡片生成器数据
// /myehr/formtemplate/cardformInitData.action
export function cardformInitData2(params) {
    const data = JSON.stringify(params)
    return request({
        url: `/formtemplate/cardformInitData.action`,
        method: 'post',
        data: data
    })
}

// 组织树
// myehr/formtemplate/cardformInitDataForTree.action?swaggerUserCode=sysadmin&params={}&ORGVORGANIZATION_ID=C1&lv=0&solutionId=17
export function cardformInitDataForTree(params, id, solutionId, nodeCode) {
    const data = JSON.stringify(params)
    return request({
        url: `/formtemplate/cardformInitDataForTree.action?params={}&${nodeCode}=${id}&lv=0&solutionId=${solutionId}`,
        method: 'post',
        data: data
    })
}

// http://119.254.89.122:9882/myehr/formtemplate/cardformInitDataForDutys.action?dutyList=学士,硕士,博士&swaggerUserCode=sysadmin
export function cardformInitDataForDutys(params, dutyList, pkcode) {
    const data = JSON.stringify(params)
    return request({
        url: `/formtemplate/cardformInitDataForDutys.action?dutyList=${dutyList}&pkCode=${pkcode}&swaggerUserCode=sysadmin`,
        method: 'post',
        data
    })
}

// http://119.254.89.122:9882/myehr/formtemplate/dutyAction.action?swaggerUserCode=sysadmin
export function dutyAction(params) {
    const data = JSON.stringify(params)
    return request({
        url: `/formtemplate/dutyAction.action?swaggerUserCode=sysadmin`,
        method: 'post',
        data
    })
}

export function getIframeUrl(formId) {
    return request({
        url: `/form/getReportUrl.action?formId=${formId}`,
        method: 'post'
    })
}

// http://119.254.89.122:9882/myehr/formtemplate/getLayoutTemplateByFormId.action?formId=5914
export function getLayoutTemplateByFormId(formId) {
    return request({
        url: `/formtemplate/getLayoutTemplateByFormId.action?formId=${formId}`,
        method: 'post'
    })
}

// http://119.254.89.122:9882/myehr/dict/getselectColumndatasByFormId.action?formId=6622
export function getselectColumndatasByFormId(formId) {
    return request({
        url: `/dict/getselectColumndatasByFormId.action?formId=${formId}`,
        method: 'get'
    })
}

// 获取导航数据
export function queryMainframeMenuBySchemeId(param) {
    return request({
        url: `/login/queryMainframeMenuBySchemeId.action?schemeId=${param.schemeId}`,
        method: 'get'
    })
}

// 刷新表单缓存
export function refreshFormCache(params) {
    const data = JSON.stringify(params)
    return request({
        url: `/cache/refreshCache.action?swaggerUserCode=sysadmin`,
        method: 'post',
        data
    })
}
// 生成表单
export function createVue(params) {
    const data = JSON.stringify(params)
    return request({
        url: `/form/getVuewHtml.action?formType=APP`,
        method: 'post',
        data
    })
}
// 部门选择器
export function thequeryTreeSolution(parms) {
    return request({
        url: `/form/queryTreeSolution.action?formId=${parms.formId}&params=${parms.params}&lv=${parms.lv}`,
        method: 'get'
    })
}
export function thequeryTreeSolution2(parms) {
    return request({
        url: `/form/queryTreeSolution.action?formId=${parms.formId}&params=${parms.params}&EMPVORGANIZATION_ID=${parms.id}&lv=${parms.lv}`,
        method: 'get'
    })
}
// 获取最近联系人
export function getLastUsers(parms) {
    return request({
        url: `/formCustom/getLastUsers.action`,
        method: 'get'
    })
}
// 获取人员选择器所有tab
export function getSelectTabs(parms) {
    return request({
        url: `/formCustom/getSelectTabs.action`,
        method: 'post',
        data: parms
    })
}
// 获取人员选择器普通列表式数据获取
export function getDataBySourseId(parms) {
    return request({
        url: `/formCustom/getDataBySourseId.action`,
        method: 'post',
        data: parms
    })
}

// 获取人员选择器 树全加载数据获取接口TREEFUNCTION：
export function getTreeSolutionByIdForAll(parms) {
    return request({
        url: `/form/getTreeSolutionByIdForAll.action?swaggerUserCode=sysadmin&solutionId=${parms.solutionId}`,
        method: 'get'
    })
}
// 获取人员选择器 树懒加载数据获取接口TREEFUNCTION_LAZY
export function getTreeSolutionByIdForItem(parms) {
    return request({
        url: `/form/getTreeSolutionById.action?solutionId=${parms.solutionId}&ORGVORGANIZATION_ID==${parms.id}&lv==${parms.lv}`,
        method: 'get',
        data: parms
    })
}
// 可发流程列表(不带分页):
export function startActProcess() {
    return request({
        url: `/act/model/getStartProcessDatas.action`,
        method: 'get'
    })
}
// 待批列表(不带分页):
export function todoForPC() {
    return request({
        url: `/act/task/todoForMobile.action?formType=PC`,
        method: 'get'
    })
}
// 普通流程已发列表(带分页)
export function historic(params) {
    const data = JSON.stringify(params)
    return request({
        url: `/act/task/historic.action`,
        method: 'post',
        data
    })
}
// 保存最近联系人
export function saveLastUsers(parms) {
    return request({
        url: `/formCustom/saveLastUser.action`,
        method: 'post',
        data: parms
    })
}
// 查询新闻公告接口
export function getNews() {
    return request({
        url: `/announcement/getAnnouncement.action`,
        method: 'post',
    })
}
// 根据状态查询新闻公告接口
export function getNewsByState(id,title) {
    return request({
        url: `/announcement/getAnnouncementByState.action?state=${id}&title=${title}`,
        method: 'get',
    })
}
// 天气预报接口
export function getWeather(cityId) {
    return request({
        url: `/announcement/WeatherReport.action?CityId=${cityId}`,
        method: 'get',
    })
}
// 查询制作的模板
export function getCardForm() {
    return request({
        url: `/CardForm/getCardForm.action`,
        method: 'get',
    })
}
//删除制作的模板
export function deleteCardForm(id) {
    return request({
        url: `/CardForm/deleteCardForm.action?Id=${id}`,
        method: 'get',
    })
}
//动态列表接口
export function getQueryDynamic(id) {
    return request({
        url: `/dynamic/queryDynamic.action?formId=8116&offset=1&limit=10&isleading=N&isRelatedPersonnel=1`,
        method: 'get',
    })
}
//Echarts数据接口
export function getNewEcharts(parms) {
    return request({
        url: `/dataSources/getNewEcharts.action`,
        method: 'post',
        data: parms
    })
}
//获取Echarts数据源接口
export function getEchartByType(parms) {
    return request({
        url: `/dataSources/getEchartByType.action?echartType=${parms.type}`,
        method: 'get',
    })
}
//获取Echarts配色接口
export function getEchartColor() {
    return request({
        url: `dataSources/getEchartColor.action`,
        method: 'get',
    })
}
//Echarts 实体树SQL查询数据接口
export function getEchartSelectFullTree(parms) {
    return request({
        url: `/dataSources/selectFullTree.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 保存SQL数据接口
export function saveDatasource(parms) {
    return request({
        url: `/dataSources/saveDatasource.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 映射SQL数据接口
export function mappingSourceColumn(parms) {
    return request({
        url: `/dataSources/mappingSourceColumn.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 圖例关联字段回显接口
export function getSourceSelect(id) {
    return request({
        url: `/dataSources/getSelect.action?dataSourseId=${id}`,
        method: 'get',
    })
}
//Echarts 字典回显接口
export function findDictList(param) {
    return request({
        url: `/dataSources/findDictList.action?order=asc&offset=${param.offset}&limit=${param.limit}&condition=${param.condition}&pageSize=${param.offset}`,
        method: 'get'
    })
}
//Echarts 详细配置保存接口
export function saveEchartConfig(form,params) {
    return request({
        url: `/dataSources/saveEchartConfig.action?type=${params.type}&recode=${params.recode}`,
        method: 'post',
        data: form
    })
}
//Echarts 数据源配置查询接口
export function loadDataSourceInfo(parms) {
    return request({
        url: `/dataSources/loadDataSourceInfo.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 数据源图例配置查询接口
export function loadechartsforSourcefo(parms) {
    return request({
        url: `/dataSources/loadechartsforSourcefo.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 数据源删除接口
export function removeDataSource(parms) {
    return request({
        url: `/dataSources/removeDataSource.action`,
        method: 'post',
        data: parms
    })
}
//Echarts 柱图接口
export function getDataXsql(parms) {
    return request({
        url: `/dataSources/getDataXsql.action`,
        method: 'post',
        data: parms
    })
}